package com.example.shortlink.dao.mapper;

import com.example.shortlink.dao.entity.LinkLocaleStats;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

public interface LinkLocaleStatsMapper extends BaseMapper<LinkLocaleStats> {

    @Insert("<script> " +
            "INSERT INTO " +
            "t_link_locale_stats " +
            "(" +
            "full_short_url, " +
            "gid, " +
            "date, " +
            "cnt, " +
            "country, " +
            "province, " +
            "city, " +
            "adcode, " +
            "create_time, " +
            "update_time, " +
            "del_flag" +
            ") " +
            "VALUES " +
            "( " +
            "#{linkLocaleStats.fullShortUrl}, " +
            "#{linkLocaleStats.gid}, " +
            "#{linkLocaleStats.date}, " +
            "#{linkLocaleStats.cnt}, " +
            "#{linkLocaleStats.country}, " +
            "#{linkLocaleStats.province}, " +
            "#{linkLocaleStats.city}, " +
            "#{linkLocaleStats.adcode}, " +
            "NOW(), " +
            "NOW(), " +
            "0 " +
            ") " +
            "ON DUPLICATE KEY UPDATE cnt = cnt +  #{linkLocaleStats.cnt}" +
            "</script>")
    void shortLinkLocaleState(@Param("linkLocaleStats") LinkLocaleStats linkLocaleStatsDO);
}